﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;

using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Data;

using System.Drawing.Imaging;
using WCSY.MODEL;
using WCSY.BLL;
using System.Web.Services;

public partial class main : System.Web.UI.Page
{
    static string UN;
    static string UI;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!Page.IsPostBack)
        {
            string userId = Session["userId"].ToString();
            string roleId = tool.getRoleIdByUserId(userId);
            UN = Session["userName"].ToString();
            UI = userId;
            if(!roleId.Equals("")){
                pareentNode(roleId);
            }

           
           
           
        }

    }
   
    public void pareentNode(string roleId)
    {
        string sql = "select a.rightsid,a.parentid,a.rightsname,a.rightstype,a.rightsurl,a.remarks"+
        " from  mg_rights as a,mg_rrrelation as b "+
        "  where a.rightsid=b.rightsid  and a.rightstype=1 "+ 
        "  and parentid='0' and b.roleid='"+roleId+"'";
        List<Mg_right> rights =  Mg_rightManager.GetMg_rightsBySql(sql) as List<Mg_right>;
        //Rights.GetChildRight(tnode.Value);
        TreeView1.Nodes.Clear();

        foreach (Mg_right t in rights)
        {
            TreeNode root = new TreeNode();
            string rootValue = t.Rightsname;
            int rootId = t.Rightsid;
            root.Text = rootValue;
            root.Value = rootId.ToString();

            
            TreeView1.Nodes.Add(root);
            root.ImageUrl = "~/image/base1.gif";
            childNodes(root);
        }
    }

    public void childNodes(TreeNode childNode)
    {
        string sql = "select rightsid,parentid,rightsname,rightstype,rightsurl,remarks from mg_rights where parentid = " + Convert.ToInt32(childNode.Value) + " and rightstype=1";
        List<Mg_right> rights = Mg_rightManager.GetMg_rightsBySql(sql) as List<Mg_right>;
        
            childNode.SelectAction = TreeNodeSelectAction.Expand;

            foreach (Mg_right c in rights)
            {
                TreeNode child = new TreeNode();
                child.Text = c.Rightsname;
                child.Value = c.Rightsid.ToString();

                childNode.ChildNodes.Add(child);
                child.ImageUrl = "~/image/folder1.gif";
                if(!c.Rightsurl.Equals("")){
                child.NavigateUrl = "JAVAscript:openUrl('" + c.Rightsurl + "');";
                }
                //child.NavigateUrl = c.Rightsurl;

                childNodes(child);
            }
        

    }

    protected void modifyUserStatus_Click(object sender, EventArgs e)
    {
        if (Session["userId"]!=null)
        {
        Mg_userManager userM = new Mg_userManager();
        string userid = Session["userId"].ToString();
        userM.ModifyMg_userStatus(userid,"0");
        }
    }
   
    [WebMethod]
    public static string returnWarning(string re)
    {
        string result="";
        DataTable dt = WarningManager.secWarningByDate();
        if(dt.Rows.Count>0){
            foreach(DataRow dr in dt.Rows){
                result += dr["descript"].ToString()+" 提交人："+dr["fillpsn"].ToString()+"\n"+"~";

            }
        }
        if (UI != null && UN.Equals("张艳玲"))
        {
            return result;
        }
        else {

            return "";
        }
        

    }

    
}